<template>
	<view class="page">
		<view class="head-back">
			<view class="back" @click="onBack">
				<text></text>
			</view>
			<view class="title">
				<text>我的订单</text>
			</view>
			<view class="more-icon">
				<view class="icon-list">
					<text class="iconfont icon-fadajing"></text>
				</view>
			</view>
		</view>
		<!-- 订单tab -->
		<view class="order-tab">
			<view class="tab" v-for="item in orderState" :class="{'action':OrderType==item.id}" @tap="onNav(item.id)" :key="item.id">
				<text>{{item.title}}</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="order-list">
			<view class="list" v-for="(item,index) in order" @click="onOrderList(item.orderid)" :key="index">
				<view class="title-status">
					<view class="title">
						<text>下单时间：{{item.createtime}}</text>
					</view>
					<view class="status">
						<text v-if="item.status == 10">待付款</text>
						<text v-if="item.status == 20">待发货</text>
						<text v-if="item.status == 30">待收货</text>
						<text v-if="item.status == 40">待评价</text>
						<text v-if="item.status == 60" style="color:#ccc;">已失效</text>
						<text class="iconfont icon-laji del"></text>
					</view>
				</view>
				<view class="goods-list">
					<view class="goods" v-for="(data, index) in item.product" :key="index">
						<view class="thumb">
							<image :src="data.img" mode=""></image>
						</view>
						<view class="item">
							<view class="goods-name">
								<text class="two-omit">{{data.name}}</text>
							</view>
							<view class="goods-price">
								<text class="min">￥</text>
								<text class="max">{{data.price}}</text>
								<!-- 							<text class="min">.00</text> -->
							</view>
						</view>
					</view>
				</view>
				<view class="status-btn">
					<view class="btn">
						<text>取消订单</text>
					</view>
					<view class="btn action">
						<text>立即支付</text>
					</view>
					<!-- 					<view class="btn action" @click.stop="onEvaluate">
						<text>评价</text>
					</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId: '', //订单id
				order: [], //订单数据
				OrderType: 0,
				orderState: [{
						id: 0,
						title: '全部',
						type: 'all'
					},
					{
						id: 10,
						title: '待付款',
						type: 'nopay'
					},
					{
						id: 20,
						title: '待发货',
						type: 'nosend'
					},
					{
						id: 30,
						title: '待收货',
						type: 'noget'
					},
					{
						id: 40,
						title: '待评价',
						type: 'nocomment'
					}
				]
			};
		},
		onLoad(params) {
			this.OrderType = params.type;
			this.getOrderDetail()
		},
		methods: {
			onNav(id) {
				this.OrderType = id;
				this.orderList = [];
				this.currentPage = 1;
				this.getOrderDetail();
			},
			//查询订单数据
			getOrderDetail() {
				console.log(this.OrderType)
				this.$api.order.getOrder({
					data: this.OrderType
				}).then((res) => {
					res.data.forEach(item => {
						item.product.forEach((item1, index, arr) => {
							arr[index] = JSON.parse(item1)
						})
						this.$url(item.product, 'img')
					})
					console.log(res.data)
					this.order = res.data
				}).catch((err) => {
					console.log('request fail', err);
				})
			},
			/**
			 * 返回点击
			 */
			onBack() {
				this.$router.go(-1)
			},
			/**
			 * 订单tab点击
			 */
			onOrderTab(type) {
				this.OrderType = type;
				// #ifdef H5
				uni.redirectTo({
					url: '/pages/MyOrderList/MyOrderList?type=' + type,
				})
				//#endif
			},
			/**
			 * 订单列表点击
			 */
			onOrderList(orderid) {
				uni.navigateTo({
					url: '/pages/OrderDetails/OrderDetails?orderId=' + orderid
				})
			},
			/**
			 * 评价点击
			 */
			onEvaluate() {
				uni.navigateTo({
					url: '/pages/MyEvaluatePush/MyEvaluatePush'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'MyOrderList.scss';
</style>
